package operation;

import book.Book;
import book.BookList;
import uesr.User;

import java.util.Scanner;

public class AddBook implements IOperation {


    @Override
    public void work(BookList bookList) {
        System.out.println("增加图书");
        if (bookList.isFull()==true){
            bookList.isFullOperation();
        }
        System.out.println("输入要增加的书名");
        Scanner scanner=new Scanner(System.in);
        String Name=scanner.nextLine();
        int currentSize=bookList.getUseSize();
        for (int i = 0; i <currentSize ; i++) {
            Book book=bookList.getBook(i);
            if (book.getName().equals(Name)){
                System.out.println("此书已有，增加失败");
                System.out.println(book);
                return;
            }
        }
        System.out.println("输入书的作者");
        String author=scanner.nextLine();
        System.out.println("输入书的价格");
        int price=scanner.nextInt();
        scanner.nextLine();
        System.out.println("输入书的类型");
        String type=scanner.nextLine();
        Book book=new Book(Name,author,price,type);
        bookList.setBook(book);
        bookList.setUseSize(currentSize+1);
        System.out.println("添加成功");
        int ret=bookList.booksLength();
        System.out.println(ret);
    }
}
